/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StartupCompanyManager2012SideProjcWork.java
 *
 * Created on 10.12.2011, 21:44:46
 */
package startupcompanymanager2012;

import java.awt.Color;
import javax.swing.JOptionPane;

/**
 *
 * @author Matthäus
 */
public class StartupCompanyManager2012SideProjcWork extends javax.swing.JFrame {

    private static int totallines = 0, completedlines = 0, bugs = 0, maxbugs = 0, status = 0, usedtime = 0, maxtime = 0, selected;
    private static double earnings = 0.00;
    public static boolean buttonWork = true, buttonDebug = false;

    /** Creates new form StartupCompanyManager2012SideProjcWork */
    public StartupCompanyManager2012SideProjcWork() {
        initComponents();
        updateStats();
        Core.calendarTimer.stop();
    }

    public static void updateStats() {
        selected = Core.runningSideProjectNum;

        earnings = Core.projc.get(selected).getEarnings();
        sideProjcEarnings.setText(Core.nfmt.format(Core.projc.get(selected).getEarnings()));

        totallines = Core.projc.get(selected).getTotalLines();
        completedlines = Core.projc.get(selected).getCompletedlines();
        sideProjcLineStatus.setText(Integer.toString(completedlines) + "/" + Integer.toString(totallines));
        lineStatusBar.setMaximum(totallines);
        lineStatusBar.setMinimum(0);
        lineStatusBar.setValue(completedlines);

        maxbugs = Core.projc.get(selected).getMaxBugs();
        bugs = Core.projc.get(selected).getBugs();
        sideProjcBugStatus.setText(Integer.toString(bugs) + "/" + Integer.toString(maxbugs));
        bugStatusBar.setMaximum(maxbugs);
        bugStatusBar.setMinimum(0);
        bugStatusBar.setValue(bugs);

        maxtime = Core.projc.get(selected).getMaxTime();
        usedtime = Core.projc.get(selected).getUsedtime();
        sideProjcTimeStatus.setText(Integer.toString(usedtime) + "/" + Integer.toString(maxtime));
        timeStatusBar.setMaximum(maxtime);
        timeStatusBar.setMinimum(0);
        timeStatusBar.setValue(usedtime);

        status = Core.projc.get(selected).getIntStatus();

        workSideProjc.setEnabled(buttonWork);
        debugSideProjc.setEnabled(buttonDebug);

        sideProjectStatusPanel.setBackground(Core.sideProjectStatus);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sideProjectWorkPanel = new javax.swing.JPanel();
        viewTitle = new javax.swing.JLabel();
        sideProjectStatusPanel = new javax.swing.JPanel();
        labelLineStatus = new javax.swing.JLabel();
        sideProjcLineStatus = new javax.swing.JLabel();
        lineStatusBar = new javax.swing.JProgressBar();
        labelBugStatus = new javax.swing.JLabel();
        sideProjcBugStatus = new javax.swing.JLabel();
        bugStatusBar = new javax.swing.JProgressBar();
        workSideProjc = new javax.swing.JButton();
        debugSideProjc = new javax.swing.JButton();
        closeView = new javax.swing.JButton();
        sideProjcEarnings = new javax.swing.JLabel();
        labelTimeStatus = new javax.swing.JLabel();
        sideProjcTimeStatus = new javax.swing.JLabel();
        timeStatusBar = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(startupcompanymanager2012.StartupCompanyManager2012App.class).getContext().getResourceMap(StartupCompanyManager2012SideProjcWork.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        sideProjectWorkPanel.setBackground(resourceMap.getColor("sideProjectWorkPanel.background")); // NOI18N
        sideProjectWorkPanel.setName("sideProjectWorkPanel"); // NOI18N

        viewTitle.setFont(resourceMap.getFont("viewTitle.font")); // NOI18N
        viewTitle.setText(resourceMap.getString("viewTitle.text")); // NOI18N
        viewTitle.setName("viewTitle"); // NOI18N

        sideProjectStatusPanel.setBackground(resourceMap.getColor("sideProjectStatusPanel.background")); // NOI18N
        sideProjectStatusPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        sideProjectStatusPanel.setName("sideProjectStatusPanel"); // NOI18N

        javax.swing.GroupLayout sideProjectStatusPanelLayout = new javax.swing.GroupLayout(sideProjectStatusPanel);
        sideProjectStatusPanel.setLayout(sideProjectStatusPanelLayout);
        sideProjectStatusPanelLayout.setHorizontalGroup(
            sideProjectStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 38, Short.MAX_VALUE)
        );
        sideProjectStatusPanelLayout.setVerticalGroup(
            sideProjectStatusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 39, Short.MAX_VALUE)
        );

        labelLineStatus.setText(resourceMap.getString("labelLineStatus.text")); // NOI18N
        labelLineStatus.setName("labelLineStatus"); // NOI18N

        sideProjcLineStatus.setText(resourceMap.getString("sideProjcLineStatus.text")); // NOI18N
        sideProjcLineStatus.setName("sideProjcLineStatus"); // NOI18N

        lineStatusBar.setName("lineStatusBar"); // NOI18N

        labelBugStatus.setText(resourceMap.getString("labelBugStatus.text")); // NOI18N
        labelBugStatus.setName("labelBugStatus"); // NOI18N

        sideProjcBugStatus.setText(resourceMap.getString("sideProjcBugStatus.text")); // NOI18N
        sideProjcBugStatus.setName("sideProjcBugStatus"); // NOI18N

        bugStatusBar.setName("bugStatusBar"); // NOI18N

        workSideProjc.setText(resourceMap.getString("workSideProjc.text")); // NOI18N
        workSideProjc.setName("workSideProjc"); // NOI18N
        workSideProjc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                workSideProject(evt);
            }
        });

        debugSideProjc.setText(resourceMap.getString("debugSideProjc.text")); // NOI18N
        debugSideProjc.setName("debugSideProjc"); // NOI18N
        debugSideProjc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                debugSideProjc(evt);
            }
        });

        closeView.setText(resourceMap.getString("closeView.text")); // NOI18N
        closeView.setName("closeView"); // NOI18N
        closeView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeView(evt);
            }
        });

        sideProjcEarnings.setText(resourceMap.getString("sideProjcEarnings.text")); // NOI18N
        sideProjcEarnings.setName("sideProjcEarnings"); // NOI18N

        labelTimeStatus.setText(resourceMap.getString("labelTimeStatus.text")); // NOI18N
        labelTimeStatus.setName("labelTimeStatus"); // NOI18N

        sideProjcTimeStatus.setText(resourceMap.getString("sideProjcTimeStatus.text")); // NOI18N
        sideProjcTimeStatus.setName("sideProjcTimeStatus"); // NOI18N

        timeStatusBar.setName("timeStatusBar"); // NOI18N

        javax.swing.GroupLayout sideProjectWorkPanelLayout = new javax.swing.GroupLayout(sideProjectWorkPanel);
        sideProjectWorkPanel.setLayout(sideProjectWorkPanelLayout);
        sideProjectWorkPanelLayout.setHorizontalGroup(
            sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(timeStatusBar, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sideProjectWorkPanelLayout.createSequentialGroup()
                        .addComponent(workSideProjc, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(debugSideProjc, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(closeView))
                    .addComponent(lineStatusBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                        .addComponent(labelLineStatus)
                        .addGap(18, 18, 18)
                        .addComponent(sideProjcLineStatus))
                    .addComponent(bugStatusBar, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                        .addComponent(labelBugStatus)
                        .addGap(18, 18, 18)
                        .addComponent(sideProjcBugStatus))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sideProjectWorkPanelLayout.createSequentialGroup()
                        .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(viewTitle)
                            .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(sideProjcEarnings)))
                        .addGap(104, 104, 104)
                        .addComponent(sideProjectStatusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                        .addComponent(labelTimeStatus)
                        .addGap(18, 18, 18)
                        .addComponent(sideProjcTimeStatus)))
                .addContainerGap())
        );
        sideProjectWorkPanelLayout.setVerticalGroup(
            sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                        .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                                .addComponent(viewTitle)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(sideProjcEarnings))
                            .addComponent(sideProjectStatusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(21, 21, 21)
                        .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(sideProjcLineStatus)
                            .addComponent(labelLineStatus))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lineStatusBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelBugStatus)
                            .addComponent(sideProjcBugStatus))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bugStatusBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(43, 43, 43)
                        .addComponent(timeStatusBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(debugSideProjc, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
                                .addComponent(workSideProjc, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(closeView)))
                    .addGroup(sideProjectWorkPanelLayout.createSequentialGroup()
                        .addGap(178, 178, 178)
                        .addGroup(sideProjectWorkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTimeStatus)
                            .addComponent(sideProjcTimeStatus))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(sideProjectWorkPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(sideProjectWorkPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void workSideProject(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_workSideProject

        int days = Integer.parseInt(JOptionPane.showInputDialog("Enter the amount of days you want to work on the side project: ", 0));
        Core.projc.get(selected).codeSideProject(days);
        Core.projc.get(selected).checkProject();

        StartupCompanyManager2012View.livelDate.setText(Core.calendar.toString());
        updateStats();


    }//GEN-LAST:event_workSideProject

    private void debugSideProjc(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_debugSideProjc
        int days = Integer.parseInt(JOptionPane.showInputDialog("Enter the amount of days you want to spend on debugging the side project: ", 0));
        Core.projc.get(selected).debugProject(days);
        Core.projc.get(selected).checkProject();
        StartupCompanyManager2012View.livelDate.setText(Core.calendar.toString());
        if (Core.runningSideProject == true) {
            updateStats();
        } else {
            dispose();
            Core.projc.clear();
        }
    }//GEN-LAST:event_debugSideProjc

    private void closeView(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeView
        if (Core.runningSideProject == false && Core.sideProjectFinished == true) {

            Core.sideProjectFinished = false;
            Core.projc.clear();


        }
        Core.calendarTimer.start();
        dispose();
    }//GEN-LAST:event_closeView

    /**
     * @param args the command line arguments
     */
    public static void init(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(StartupCompanyManager2012SideProjcWork.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(StartupCompanyManager2012SideProjcWork.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(StartupCompanyManager2012SideProjcWork.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(StartupCompanyManager2012SideProjcWork.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new StartupCompanyManager2012SideProjcWork().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JProgressBar bugStatusBar;
    private javax.swing.JButton closeView;
    public static javax.swing.JButton debugSideProjc;
    private javax.swing.JLabel labelBugStatus;
    private javax.swing.JLabel labelLineStatus;
    private javax.swing.JLabel labelTimeStatus;
    public static javax.swing.JProgressBar lineStatusBar;
    public static javax.swing.JLabel sideProjcBugStatus;
    public static javax.swing.JLabel sideProjcEarnings;
    public static javax.swing.JLabel sideProjcLineStatus;
    public static javax.swing.JLabel sideProjcTimeStatus;
    public static javax.swing.JPanel sideProjectStatusPanel;
    private javax.swing.JPanel sideProjectWorkPanel;
    public static javax.swing.JProgressBar timeStatusBar;
    private javax.swing.JLabel viewTitle;
    public static javax.swing.JButton workSideProjc;
    // End of variables declaration//GEN-END:variables
}
